using GameConfig.item;

namespace GameLogic
{
    class m_BagItemList : UILoopItemWidget, IListDataItem<m_BagItemListData>
    {
        #region 脚本工具生成的代码
        private SlotBagRow _slotUIRow;
        protected override void ScriptGenerator()
        {
            _slotUIRow = this.gameObject.GetComponent<SlotBagRow>();
        }
        #endregion

        #region 事件
        private void OnClickBtn()
        {
            //Debug.Log("点击当前数据" + _textDes.text);
        }
        #endregion

        /// <summary>
        /// 设置数据
        /// </summary>
        /// <param name="d"></param>
        public void SetItemData(m_BagItemListData d)
        {
            this.gameObject.SetActive(true);
            for (int i = 0; i < _slotUIRow.slotUIBags.Length; i++)
            {
                if (d.m_BagDatas.Count-1 >= i)
                {
                    if (d.m_BagDatas[i] != null)
                    {
                        if (ConfigSystem.Instance.Tables.TbItem.DataMap.ContainsKey(d.m_BagDatas[i].id))
                        {
                            ItemTb itemTb = ConfigSystem.Instance.Tables.TbItem.Get(d.m_BagDatas[i].id);
                            _slotUIRow.slotUIBags[i].UpdateSlot(itemTb, d.m_BagDatas[i].amount);
                        }
                        else
                        {
                            _slotUIRow.slotUIBags[i].UpdateSlot(null, d.m_BagDatas[i].amount);
                        }
                    }
                }
                else
                {
                    _slotUIRow.slotUIBags[i].UpdateSlot(null, 0);
                }
            }
        }
    }
}

